package com.cxx.purchasecharge.core.model.persistence;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.cxx.purchasecharge.core.model.BaseModel;
import com.cxx.purchasecharge.core.model.ResourceType;

/**
 * 系统资源(如url或method)
 */
@Entity
@Table (name = "pc_resource")
public class Resource extends BaseModel
{
    private static final long serialVersionUID = 1L;

    private long id;
    private String name;
    private String value;
    private ResourceType type = ResourceType.URL;
    private int priority;
    private String description;
    private boolean enable = true;
    private boolean system = false;

    private List <Authority> authorities;
    
    public Resource () {}
    
    public Resource (String name) 
    {
        this.name = name;
    }

    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    public long getId ()
    {
        return id;
    }

    public void setId (long id)
    {
        this.id = id;
    }

    @Column (unique = true, nullable = false)
    public String getName ()
    {
        return name;
    }

    public void setName (String name)
    {
        this.name = name;
    }

    @Column (nullable = false)
    public String getValue ()
    {
        return value;
    }

    public void setValue (String value)
    {
        this.value = value;
    }

    public ResourceType getType ()
    {
        return type;
    }

    public void setType (ResourceType type)
    {
        this.type = type;
    }

    public int getPriority ()
    {
        return priority;
    }

    public void setPriority (int priority)
    {
        this.priority = priority;
    }

    public String getDescription ()
    {
        return description;
    }

    public void setDescription (String description)
    {
        this.description = description;
    }

    public boolean isEnable ()
    {
        return enable;
    }

    public void setEnable (boolean enable)
    {
        this.enable = enable;
    }

    public boolean isSystem ()
    {
        return system;
    }

    public void setSystem (boolean system)
    {
        this.system = system;
    }

    @ManyToMany (mappedBy = "resources")
    public List <Authority> getAuthorities ()
    {
        return authorities;
    }

    public void setAuthorities (List <Authority> authorities)
    {
        this.authorities = authorities;
    }
}
